package com.spsoft.vatoutinv.service.vmsclassifycode.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spsoft.core.enums.ResponseEnum;
import com.spsoft.core.model.Result;
import com.spsoft.core.model.bo.TokenUser;
import com.spsoft.core.model.leqidmz.param.QueryClassifyCodeParams;
import com.spsoft.core.model.leqidmz.response.QueryClassifyCodeVO;
import com.spsoft.core.utils.BeanUtils;
import com.spsoft.core.utils.ExcelUtils;
import com.spsoft.core.utils.SecurityUtils;
import com.spsoft.core.utils.StringUtil;
import com.spsoft.einvoicetodmz.service.DmzApiClientService;
import com.spsoft.system.service.DefBizdictService;
import com.spsoft.vatoutinv.constants.CommonConstant;
import com.spsoft.vatoutinv.constants.DictConstant;
import com.spsoft.vatoutinv.entity.vmsavalibletaxrate.VmsAvalibleTaxRate;
import com.spsoft.vatoutinv.entity.vmsclassifycode.VmsClassifyCode;
import com.spsoft.vatoutinv.entity.vmsclassifycode.VmsClassifyCodeLog;
import com.spsoft.vatoutinv.entity.vmsclassifycode.VmsClassifyCodeLogBase;
import com.spsoft.vatoutinv.entity.vmsclassifycode.VmsClassifyCodeLogIndustry;
import com.spsoft.vatoutinv.entity.vmsfullbswjmanager.VmsFullBswjManager;
import com.spsoft.vatoutinv.enums.CommonEnum;
import com.spsoft.vatoutinv.mapper.VmsClassifyCodeMapper;
import com.spsoft.vatoutinv.model.dto.vmsclassifycode.VmsClassIfyCodeLogDetailPageDto;
import com.spsoft.vatoutinv.model.dto.vmsclassifycode.VmsClassifyCodeLogBasePageDto;
import com.spsoft.vatoutinv.model.dto.vmsclassifycode.VmsClassifyCodePageDto;
import com.spsoft.vatoutinv.model.vo.vmsclassifycode.VmsClassifyCodeDetailVO;
import com.spsoft.vatoutinv.model.vo.vmsclassifycode.VmsClassifyCodeLogBasePageVO;
import com.spsoft.vatoutinv.model.vo.vmsclassifycode.VmsClassifyCodePageVOList;
import com.spsoft.vatoutinv.service.vmsavalibletaxrate.VmsAvalibleTaxRateService;
import com.spsoft.vatoutinv.service.vmsclassifycode.VmsClassifyCodeLogBaseService;
import com.spsoft.vatoutinv.service.vmsclassifycode.VmsClassifyCodeLogIndustryService;
import com.spsoft.vatoutinv.service.vmsclassifycode.VmsClassifyCodeLogService;
import com.spsoft.vatoutinv.service.vmsclassifycode.VmsClassifyCodeService;
import com.spsoft.vatoutinv.service.vmsfullbswjmanager.VmsFullBswjManagerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

/**
 * <p>
 * 税收分类编码信息列表表 服务实现类
 * </p>
 *
 * @author wangy
 * @since 2023-11-23
 */
@Slf4j
@Service
@RequiredArgsConstructor
@SuppressWarnings("unchecked")
public class VmsClassifyCodeServiceImpl extends ServiceImpl<VmsClassifyCodeMapper, VmsClassifyCode> implements VmsClassifyCodeService {

    public static final String LOG_MSG = "(税收分类编码实现层)";

    private final DefBizdictService dictService;

    private final DmzApiClientService dmzApiClientService;

    private final VmsClassifyCodeLogService classifyCodeLogService;

    private final VmsClassifyCodeLogBaseService classifyCodeLogBaseService;

    private final VmsClassifyCodeLogIndustryService classifyCodeLogIndustryService;

    private final VmsFullBswjManagerService vmsFullBswjManagerService;

    private final VmsAvalibleTaxRateService vmsAvalibleTaxRateService;


    @Override
    public Result<VmsClassifyCodeDetailVO> getCodeDetail(String id) {
        VmsClassifyCode entity = getInfoBySphfwssflhbbm(id);
        if (ObjectUtil.isEmpty(entity)) {
            return Result.ERROR(ResponseEnum.PARAM_VALIDATED_ERROR);
        }
        VmsClassifyCodeDetailVO vo = new VmsClassifyCodeDetailVO();
        if (StringUtil.isNotEmpty(entity.getZzssl())) {
            ArrayList<String> list = new ArrayList<>(Arrays.asList(entity.getZzssl().split("、")));
            // todo 未来需求可能还要求放开
//            list.add("0%");
            vo.setZzssl(list);
            vo.setSelectZzssl(vo.getZzssl().get(0));
        }
        vo.setJsff(dictService.getDefBIzdictByLxdm(DictConstant.VMS_JSFF).getData());
        vo.setZsxm(dictService.getDefBIzdictByLxdm(DictConstant.VMS_ZSXM).getData());
        vo.setYhzcbs(dictService.getDefBIzdictByLxdm(DictConstant.VMS_YHZCBS).getData());
        return Result.OK(vo);
    }

    /**
     * 根据商品 获取 分类编码信息
     *
     * @param sphfwssflhbbm
     * @return
     */
    private VmsClassifyCode getInfoBySphfwssflhbbm(String sphfwssflhbbm) {
        return getOne(new LambdaQueryWrapper<VmsClassifyCode>()
                .eq(VmsClassifyCode::getSphfwssflhbbm, sphfwssflhbbm)
                .eq(VmsClassifyCode::getDeptCode, SecurityUtils.getDeptCode())
        );
    }

    @Override
    public Result<IPage<VmsClassifyCodePageVOList>> getCodePage(VmsClassifyCodePageDto dto) {
        Integer pageNo = dto.getPageNo();
        Integer pageSize = dto.getPageSize();

        // 获得最近一次查询结果 - 首次页面加载查询
        LambdaQueryWrapper<VmsClassifyCode> lq = new LambdaQueryWrapper<VmsClassifyCode>()
                .eq(StringUtil.isNotEmpty(dto.getSphfwssflhbbm()), VmsClassifyCode::getSphfwssflhbbm, dto.getSphfwssflhbbm())
                .likeRight(StringUtil.isNotEmpty(dto.getSphfwmc()), VmsClassifyCode::getSphfwmc, dto.getSphfwmc())
                .likeRight(StringUtil.isNotEmpty(dto.getSphfwfljc()), VmsClassifyCode::getSphfwfljc, dto.getSphfwfljc())
                .eq(VmsClassifyCode::getDeptCode, SecurityUtils.getDeptCode())
                .orderByDesc(VmsClassifyCode::getCreateTime, VmsClassifyCode::getId);
        IPage<VmsClassifyCodePageVOList> page = this.page(new Page<>(pageNo, pageSize), lq).convert(item -> {
            VmsClassifyCodePageVOList vo = new VmsClassifyCodePageVOList();
            BeanUtils.copyBeanProp(vo, item);
            return vo;
        });

        // 最后更新时间
        if (CollectionUtil.isNotEmpty(page.getRecords())) {
            Page<VmsClassifyCodeLogBase> logBasePage = new Page<>(1, 1);
            LambdaQueryWrapper<VmsClassifyCodeLogBase> query = new LambdaQueryWrapper<>();
            query.eq(VmsClassifyCodeLogBase::getDeptCode, SecurityUtils.getDeptCode());
            query.orderByDesc(VmsClassifyCodeLogBase::getId);
            Page<VmsClassifyCodeLogBase> IPage = classifyCodeLogBaseService.page(logBasePage, query);
            if (CollectionUtil.isNotEmpty(IPage.getRecords())) {
                page.getRecords().get(0).setCreateTime(IPage.getRecords().get(0).getCreateTime());
            }
        }
        return Result.OK(page);
    }

    @Override
    public Result<IPage<VmsClassifyCodeLogBasePageVO>> getBasePage(VmsClassifyCodeLogBasePageDto dto) {
        Integer pageNo = dto.getPageNo();
        Integer pageSize = dto.getPageSize();
        LambdaQueryWrapper<VmsClassifyCodeLogBase> lq = new LambdaQueryWrapper<VmsClassifyCodeLogBase>()
                .like(StringUtil.isNotEmpty(dto.getCreateUsername()), VmsClassifyCodeLogBase::getCreateUsername, dto.getCreateUsername())
                .eq(StringUtil.isNotEmpty(dto.getOperateStatus()), VmsClassifyCodeLogBase::getOperateStatus, dto.getOperateStatus())
                .and((StringUtil.isNotEmpty(dto.getStartTime()) || StringUtil.isNotEmpty(dto.getEndTime())), wrapper -> wrapper
                        .apply(StringUtil.isNotEmpty(dto.getStartTime()), "CREATE_TIME >= to_timestamp('" + dto.getStartTime() + "', 'YYYY-MM-DD HH24:MI:SS')")
                        .apply(StringUtil.isNotEmpty(dto.getEndTime()), "CREATE_TIME <= to_timestamp('" + dto.getEndTime() + "', 'YYYY-MM-DD HH24:MI:SS')")
                )
                .eq(VmsClassifyCodeLogBase::getDeptCode, SecurityUtils.getDeptCode())
                .orderByDesc(VmsClassifyCodeLogBase::getCreateTime, VmsClassifyCodeLogBase::getId);

        IPage<VmsClassifyCodeLogBasePageVO> page = classifyCodeLogBaseService.page(new Page<>(pageNo, pageSize), lq).convert(item -> {
            VmsClassifyCodeLogBasePageVO vo = new VmsClassifyCodeLogBasePageVO();
            BeanUtils.copyBeanProp(vo, item);
            // 调用乐企结果为成功，不返回前端执行结果，防止operateMsg字段过长
            if (CommonEnum.LEQI_RETURN_CODE_SUCCESS.getKey().equals(item.getOperateStatus())) {
                vo.setOperateMsg(null);
            }
            return vo;
        });
        return Result.OK(page);
    }

    @Override
    public Result<IPage<VmsClassifyCodePageVOList>> getBaseDetailPage(VmsClassIfyCodeLogDetailPageDto dto) {
        // 分页
        int pageNo = dto.getPageNo();
        int pageSize = dto.getPageSize();
        Page<VmsClassifyCodeLog> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<VmsClassifyCodeLog> lq = new LambdaQueryWrapper<VmsClassifyCodeLog>()
                .eq(VmsClassifyCodeLog::getLogBaseId, dto.getId())
                .orderByDesc(VmsClassifyCodeLog::getId);
        IPage<VmsClassifyCodeLog> IPage = classifyCodeLogService.page(page, lq);
        IPage<VmsClassifyCodePageVOList> pageResult = IPage.convert(item -> {
            VmsClassifyCodePageVOList vo = new VmsClassifyCodePageVOList();
            BeanUtils.copyBeanProp(vo, item);
            return vo;
        });
        return Result.OK(pageResult);
    }

    @Override
    public void exportDetailList(String id, HttpServletResponse response) {
        List<VmsClassifyCodeLog> list = classifyCodeLogService.list(new LambdaQueryWrapper<VmsClassifyCodeLog>()
                .eq(VmsClassifyCodeLog::getLogBaseId, id)
                .orderByDesc(VmsClassifyCodeLog::getId));
        List<VmsClassifyCodePageVOList> vos = BeanUtils.copyListProperties(list, VmsClassifyCodePageVOList::new);
        export(response, vos);
    }

    @Override
    public void exportCode(String sphfwssflhbbm, String sphfwmc, String sphfwfljc, HttpServletResponse response) {
        // 查询导出数据
        LambdaQueryWrapper<VmsClassifyCode> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtil.isNotEmpty(sphfwssflhbbm), VmsClassifyCode::getSphfwssflhbbm, sphfwssflhbbm);
        queryWrapper.likeRight(StringUtil.isNotEmpty(sphfwmc), VmsClassifyCode::getSphfwmc, sphfwmc);
        queryWrapper.likeRight(StringUtil.isNotEmpty(sphfwfljc), VmsClassifyCode::getSphfwfljc, sphfwfljc);
        queryWrapper.eq(VmsClassifyCode::getDeptCode, SecurityUtils.getDeptCode());
        queryWrapper.orderByDesc(VmsClassifyCode::getCreateTime, VmsClassifyCode::getId);

        List<VmsClassifyCode> classifyCodeList = this.list(queryWrapper);
        List<VmsClassifyCodePageVOList> vmsClassifyCodePageVOList = BeanUtils.copyListProperties(classifyCodeList, VmsClassifyCodePageVOList::new);
        // 导出
        export(response, vmsClassifyCodePageVOList);
    }

    private void export(HttpServletResponse response, List<VmsClassifyCodePageVOList> data) {
        for (int i = 0; i < data.size(); i++) {
            VmsClassifyCodePageVOList item = data.get(i);
            item.setXh(i + 1);
            item.setSfhzx(dictService.getDefBIzdictNameByLxdm(DictConstant.VMS_YESORNO).get(item.getSfhzx()));
            item.setTdyslxdm(dictService.getDefBIzdictNameByLxdm(DictConstant.VMS_TDYSBQGL).get(item.getTdyslxdm()));
            item.setCezs(dictService.getDefBIzdictNameByLxdm(DictConstant.VMS_YESORNO).get(item.getCezs()));
            item.setBzs(dictService.getDefBIzdictNameByLxdm(DictConstant.VMS_YESORNO).get(item.getBzs()));
            String s = dictService.getDefBIzdictNameByLxdm(DictConstant.VMS_JZJTDM).get(item.getJzjtdm());
            if (StringUtil.isNotEmpty(s)) {
                item.setJzjtdm(s);
            } else {
                item.setJzjtdm(item.getJzjtdm());
            }
        }
        try {
            ExcelUtils.exportExcel(data, VmsClassifyCodePageVOList.class, "税收分类编码", response);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result<Object> getClassifyCodeByLq(QueryClassifyCodeParams params, TokenUser tokenUser) {
        // 获取省级税务机关代码
        VmsFullBswjManager bswjManager = vmsFullBswjManagerService.getOneByWhjg(tokenUser.getDeptCode());
        params.setSjswjgdm(bswjManager.getQydm());
        // 获取上次下载返回的时间戳
        Page<VmsClassifyCode> page = new Page<>(1, 1);
        LambdaQueryWrapper<VmsClassifyCode> query = new LambdaQueryWrapper<>();
        query.eq(VmsClassifyCode::getDeptCode, tokenUser.getDeptCode());
        query.orderByDesc(VmsClassifyCode::getId);
        Page<VmsClassifyCode> pageResult = this.page(page, query);
        if (CollectionUtil.isNotEmpty(pageResult.getRecords())) {
            params.setSjc(DateUtil.format(pageResult.getRecords().get(0).getSjc(), CommonConstant.DATE_FORMAT_14_SHORT));
        } else {
            params.setSjc(null);
        }
        // 调用乐企接口获取税收分类编码信息
        Result<QueryClassifyCodeVO> result = dmzApiClientService.queryClassifyCode(params, null);

        // 先记录日志操作(LOG_BASE)和乐企返回的当次税收分类编码记录(LOG)
        VmsClassifyCodeLogBase vmsClassifyCodeLogBase = new VmsClassifyCodeLogBase();
        vmsClassifyCodeLogBase.setDeptCode(tokenUser.getDeptCode());
        vmsClassifyCodeLogBase.setNsrsbh(params.getNsrsbh());
        vmsClassifyCodeLogBase.setCreateTime(new Date());
        vmsClassifyCodeLogBase.setCreateUser(tokenUser.getUserCode());
        vmsClassifyCodeLogBase.setCreateUsername(tokenUser.getUserName());

        if (ResponseEnum.SUCCESS.getCode().equals(result.getCode())) {
            log.info("{}调用DMZ查询税收分类编码信息成功", LOG_MSG);
            QueryClassifyCodeVO data = result.getData();

            vmsClassifyCodeLogBase.setLogCount(data.getCount());
            vmsClassifyCodeLogBase.setSjc(data.getSjc());
            vmsClassifyCodeLogBase.setOperateStatus(CommonConstant.STR_01);
            vmsClassifyCodeLogBase.setOperateMsg(JSONObject.toJSONString(data));
            // 记录日志操作(LOG_BASE表)
            classifyCodeLogBaseService.save(vmsClassifyCodeLogBase);

            List<QueryClassifyCodeVO.ClassifyCodeInfo> ssbmList = data.getSsbmList();
            if (CollectionUtil.isNotEmpty(ssbmList)) {
                for (QueryClassifyCodeVO.ClassifyCodeInfo ssbm : ssbmList) {
                    // 保存或更新乐企返回的当次税收分类编码记录(VMS_CLASSIFY_CODE表)
                    VmsClassifyCode vmsClassifyCode = new VmsClassifyCode();
                    BeanUtils.copyProperties(ssbm, vmsClassifyCode);
                    vmsClassifyCode.setLogBaseId(vmsClassifyCodeLogBase.getId());
                    vmsClassifyCode.setDeptCode(tokenUser.getDeptCode());
                    vmsClassifyCode.setNsrsbh(params.getNsrsbh());
                    vmsClassifyCode.setCount(data.getCount());
                    vmsClassifyCode.setSjc(data.getSjc());
                    vmsClassifyCode.setUpdateTime(new Date());
                    vmsClassifyCode.setUpdateUser(tokenUser.getUserCode());
                    vmsClassifyCode.setUpdateUsername(tokenUser.getUserName());

                    // 获取税收分类编码是增量下载，本地有则更新，没有则新增
                    LambdaQueryWrapper<VmsClassifyCode> wrapper = new LambdaQueryWrapper<>();
                    wrapper.eq(VmsClassifyCode::getSphfwssflhbbm, ssbm.getSphfwssflhbbm());
                    wrapper.eq(VmsClassifyCode::getDeptCode, tokenUser.getDeptCode());
                    VmsClassifyCode classifyCode = this.getOne(wrapper);
                    if (classifyCode == null) {
                        vmsClassifyCode.setCreateTime(new Date());
                        vmsClassifyCode.setCreateUser(tokenUser.getUserCode());
                        vmsClassifyCode.setCreateUsername(tokenUser.getUserName());
                        this.save(vmsClassifyCode);
                    } else {
                        vmsClassifyCode.setId(classifyCode.getId());
                        this.updateById(vmsClassifyCode);

                        // 如果数据库存在本次返回的税收编码，删除历史行业信息记录，后续统一重新入库
                        LambdaQueryWrapper<VmsClassifyCodeLogIndustry> industryQuery = new LambdaQueryWrapper<>();
                        industryQuery.eq(VmsClassifyCodeLogIndustry::getClassifyCodeId, classifyCode.getId());
                        classifyCodeLogIndustryService.remove(industryQuery);
                    }

                    // 记录乐企返回的当次税收分类编码记录(VMS_CLASSIFY_CODE_LOG表)
                    VmsClassifyCodeLog vmsClassifyCodeLog = new VmsClassifyCodeLog();
                    BeanUtils.copyProperties(ssbm, vmsClassifyCodeLog);
                    vmsClassifyCodeLog.setLogBaseId(vmsClassifyCodeLogBase.getId());
                    vmsClassifyCodeLog.setDeptCode(tokenUser.getDeptCode());
                    vmsClassifyCodeLog.setNsrsbh(params.getNsrsbh());
                    vmsClassifyCodeLog.setCount(data.getCount());
                    vmsClassifyCodeLog.setSjc(data.getSjc());
                    classifyCodeLogService.save(vmsClassifyCodeLog);

                    // 记录乐企返回的当次税收分类编码行业信息记录(VMS_CLASSIFY_CODE_LOG_INDUSTRY表)
                    List<QueryClassifyCodeVO.HydmInfo> zspmList = ssbm.getZspmList();
                    if (CollectionUtil.isNotEmpty(zspmList)) {
                        List<VmsClassifyCodeLogIndustry> vmsClassifyCodeLogIndustryList = BeanUtils.copyListProperties(zspmList, VmsClassifyCodeLogIndustry::new, (s, t) -> {
                            t.setClassifyCodeId(vmsClassifyCode.getId());
                            t.setLogId(vmsClassifyCodeLog.getId());
                            t.setLogBaseId(vmsClassifyCodeLogBase.getId());
                            t.setDeptCode(tokenUser.getDeptCode());
                            t.setNsrsbh(params.getNsrsbh());
                            t.setCount((long) zspmList.size());
                        });
                        classifyCodeLogIndustryService.saveBatch(vmsClassifyCodeLogIndustryList);
                    }
                }
            }
        } else {
            log.error("{}调用DMZ查询税收分类编码信息失败，原因：{}", LOG_MSG, result.getMessage());
            vmsClassifyCodeLogBase.setOperateStatus(CommonConstant.STR_02);
            vmsClassifyCodeLogBase.setOperateMsg(result.getMessage());
            classifyCodeLogBaseService.save(vmsClassifyCodeLogBase);
            return Result.ERROR(result.getCode(), result.getMessage());
        }
        return Result.OK_MSG(ResponseEnum.LEQI_SUCCESS.getMsg());
    }

    @Override
    public Result<Object> queryCodeAndTax(String code, BigDecimal tax, String deptCode) {
        if (StringUtil.isNotEmpty(code) && tax != null && StringUtil.isNotEmpty(deptCode)) {
            // 根据商品编码和机构编码和当前日期查询 在有效期的税收分类编码
            LambdaQueryWrapper<VmsClassifyCode> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(VmsClassifyCode::getSphfwssflhbbm, code);
            wrapper.eq(VmsClassifyCode::getDeptCode, deptCode);
            List<VmsClassifyCode> classifyCodeList = this.list(wrapper);
            // 启用日期、停用日期非必填项，无法从数据库层面筛选
            if (CollectionUtil.isNotEmpty(classifyCodeList)) {
                Iterator<VmsClassifyCode> iterator = classifyCodeList.iterator();
                while (iterator.hasNext()) {
                    VmsClassifyCode vmsClassifyCode = iterator.next();
                    // 当前日期小于启用日期，移除当前数据
                    if (vmsClassifyCode.getQyrq() != null
                            && DateUtil.compare(new Date(), vmsClassifyCode.getQyrq()) < 0) {
                        iterator.remove();
                    }
                    // 当前日期大于停用日期，移除当前数据
                    if (vmsClassifyCode.getTyrq() != null
                            && DateUtil.compare(new Date(), vmsClassifyCode.getTyrq()) > 0) {
                        iterator.remove();
                    }
                }
            }
            if (CollectionUtil.isEmpty(classifyCodeList)) {
                return Result.ERROR(ResponseEnum.CODE_NOT_FOUND_ERROR);
            }
            for (VmsClassifyCode classifyCode : classifyCodeList) {
                if (CommonConstant.STR_Y.equals(classifyCode.getSfhzx())) {
                    return Result.ERROR(String.format(ResponseEnum.CODE_SFHZX_ERROR.getMsg(), classifyCode.getSphfwssflhbbm()));
                }
            }

            // 税收分类编码存在，校验可用税率
            List<VmsAvalibleTaxRate> taxRateList = vmsAvalibleTaxRateService.list(new LambdaQueryWrapper<VmsAvalibleTaxRate>()
                    .eq(VmsAvalibleTaxRate::getDeptCode, deptCode)
                    .eq(VmsAvalibleTaxRate::getSlzsl, tax)
                    .eq(VmsAvalibleTaxRate::getCszt, CommonConstant.STR_0));
            if (CollectionUtil.isNotEmpty(taxRateList)) {
                Iterator<VmsAvalibleTaxRate> iterator = taxRateList.iterator();
                while (iterator.hasNext()) {
                    VmsAvalibleTaxRate taxRate = iterator.next();
                    // 当前日期小于有效期起，移除当前数据
                    if (taxRate.getYxqq() != null
                            && DateUtil.compare(new Date(), taxRate.getYxqq()) < 0) {
                        iterator.remove();
                    }
                    // 当前日期大于有效期止，移除当前数据
                    if (taxRate.getYxqz() != null
                            && DateUtil.compare(new Date(), taxRate.getYxqz()) > 0) {
                        iterator.remove();
                    }
                    // 当前日期大于停用日期，移除当前数据
                    if (taxRate.getTyrq() != null
                            && DateUtil.compare(new Date(), taxRate.getTyrq()) > 0) {
                        iterator.remove();
                    }
                }
            }
            if (CollectionUtil.isEmpty(taxRateList)) {
                return Result.ERROR(ResponseEnum.SLV_NOT_FOUND_ERROR);
            }
        } else {
            return Result.ERROR(ResponseEnum.CODE_SLV_NOT_FOUND_ERROR);
        }
        return Result.OK();
    }
}
